from django.db import models

# Create your models here.


# 交易所
class Exchange(models.Model):
    exchange_name = models.CharField('交易所名字',max_length=30)
    exchange_code = models.CharField('交易所code',max_length=6)
    exchange_address = models.CharField('交易所网址',max_length=200)
    exchange_num_all = models.IntegerField('币总数')


# 币
class VirtualCoin(models.Model):
    coin_name = models.CharField('币名字',max_length=10)
    coin_acronym = models.CharField('币缩写',max_length=30)
    coin_icon = models.CharField('icon图标',max_length=1024)
    coin_rank_list = models.IntegerField('排行榜')
    coin_now_price = models.DecimalField('当前价格',max_digits=12,decimal_places=2)
    coin_value = models.DecimalField('市值',max_digits=12,decimal_places=2)
    coin_oneday_turnover = models.IntegerField('24成交量')
    coin_lowest = models.IntegerField('最低')
    coin_highest = models.IntegerField('最高')


# 交易对现价
class DealValue(models.Model):
    ONOFF_CHOICE = (
        ('1','开'),
        ('2','关')
    )
    coin_virtual = models.ForeignKey(VirtualCoin,on_delete=models.CASCADE,verbose_name='虚拟货币id',related_name='coin_virtual')
    coin_real = models.ForeignKey(VirtualCoin,on_delete=models.CASCADE,verbose_name='市场流通货币id',related_name='coin_real')
    ex_id = models.ForeignKey(Exchange, on_delete=models.CASCADE, verbose_name='交易所')
    day_limit = models.IntegerField('24h成交额度')
    trading_name = models.CharField('交易对名字',max_length=64)
    on_off = models.CharField('是否显示开关',max_length=1,choices=ONOFF_CHOICE,default=2)
    open = models.IntegerField('开')
    high = models.IntegerField('高')
    down = models.IntegerField('低')
    collect = models.IntegerField('收')
    price_limit = models.IntegerField('涨跌幅')


# 币历史数据
class TrendHistory(models.Model):
    bite_id = models.ForeignKey(VirtualCoin, on_delete=models.CASCADE, verbose_name='币')
    price_now = models.IntegerField('当前价格')
    belong_time = models.DateTimeField('价格所属时间',auto_now_add=True)


# 交易对历史表
class DealHistory(models.Model):
    deal_history = models.ForeignKey(VirtualCoin, on_delete=models.CASCADE, verbose_name='币')
    ex_id = models.ForeignKey(Exchange, on_delete=models.CASCADE, verbose_name='交易所')
    trading_name = models.CharField('交易对名字',max_length=64)
    open = models.IntegerField('开')
    high = models.IntegerField('高')
    down = models.IntegerField('低')
    collect = models.IntegerField('收')
    belong_time = models.DateTimeField('所属时间', auto_now_add=True)


# k线m15
class KlineMone(models.Model):
    deal_history = models.ForeignKey(VirtualCoin, on_delete=models.CASCADE, verbose_name='币')
    ex_id = models.ForeignKey(Exchange, on_delete=models.CASCADE, verbose_name='交易所')
    trading_name = models.CharField('交易对名字', max_length=64)
    open = models.IntegerField('开')
    high = models.IntegerField('高')
    down = models.IntegerField('低')
    collect = models.IntegerField('收')
    belong_time = models.DateTimeField('所属时间', auto_now_add=True)
    price_change = models.IntegerField('涨跌幅')
    minute_num = models.IntegerField('一分钟成交量')
    minute_change = models.IntegerField('一分钟成交额度')


# k线m15
class KlineMfifteen(models.Model):
    deal_history = models.ForeignKey(VirtualCoin, on_delete=models.CASCADE, verbose_name='币')
    ex_id = models.ForeignKey(Exchange, on_delete=models.CASCADE, verbose_name='交易所')
    trading_name = models.CharField('交易对名字', max_length=64)
    open = models.IntegerField('开')
    high = models.IntegerField('高')
    down = models.IntegerField('低')
    collect = models.IntegerField('收')
    belong_time = models.DateTimeField('所属时间', auto_now_add=True)
    price_change = models.IntegerField('涨跌幅')
    minute_num = models.IntegerField('十五分钟成交量')
    minute_change = models.IntegerField('十五分钟成交额度')




